﻿using System;


using System.Text;
using IAM.Interface.Model.Interface;
using IAM.Interface.Model.ENUM;
using System.Web;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 单个可设置模块的配置信息
    /// </summary>
    public class Module : AbstractConvertObject,IConvertXml
    {
        #region 属性
        private string _id = "";
        private string _display = "";
        private ModuleType _type = ModuleType.Delegate;
        /// <summary>
        /// 模块的唯一标识
        /// </summary>
        public string ID
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }
        /// <summary>
        /// 模块的显示名称
        /// </summary>
        public string Display
        {
            get
            {
                return _display;
            }
            set
            {
                _display = value;
            }
        }
        /// <summary>
        /// 可以进行代理操作的类型
        /// </summary>
        public ModuleType Type
        {
            get
            {
                return _type;
            }
            set
            {
                _type = value;
            }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append(" <Module");
                _xml.Append(" ID=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.ID )+ "\" ");
                _xml.Append(" Display=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Display )+ "\" ");
                _xml.Append(" Type=\"" + this.Type.ToString()+ "\" ");
                _xml.Append(" />");
                return _xml.ToString();
            }

        }

        public string XMLFinis
        {
            get
            {
                return "";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            //1.获取当前结点
            this.ID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["ID"].InnerText);
            this.Display = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Display"].InnerText);
            string strType = this.CurrentXmlNode.Attributes["Type"].InnerText;
            switch (strType.ToLower())
            {
                case "delegate":
                    this.Type = ModuleType.Delegate;
                    break;
                case "operateas":
                    this.Type = ModuleType.OperateAs;
                    break;
                case "both":
                    this.Type = ModuleType.Both;
                    break;
            }
            
            return this;
        }
        #endregion
    }
}
